//
//  VisitorTableViewController.swift
//  01- 搭建框架
//
//  Created by as888 on 15/10/16.
//  Copyright © 2015年 任伟. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    ///用户登录标记
    private var userLogin = UserAccountViewModel.sharedUserAccount.userLogon
    
    ///访客视图
    var visitorView: VisitorView?
    
    override func loadView() {

       //根据用户的登录情况，决定显示的根视图
        userLogin ? super.loadView() : setupVisitorView()
        
    }
    
    ///设置访客视图 － 每一个小函数
    private func setupVisitorView() {
    
        //替换视图
        visitorView = VisitorView()
        
        view = visitorView

        // 添加监听方法
        visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
    }
   
}

// MARK: - 访客视图监听方法
extension VisitorTableViewController {
    
    func visitorViewDidRegister() {
        print("注册a ")
    }
    
    func visitorViewDidLogin() {
        print("登录")
        
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}
